package com.Utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Random;

/**
 * @ClassName UdpSender
 * @Author lenovo
 * @Date 2023/12/5 14:02
 * @Version 1.0
 * @Description TODO
 **/
public class UdpSender {
    public static void main(String[] args) throws IOException {
        DatagramSocket datagramSocket = new DatagramSocket(9900);
        BufferedReader bufferedReader = null;
        String data = null;
        byte[] datas = null;
        DatagramPacket datagramPacket = null;
        Random random = new Random();
        while (true){
            //准备数据  控制台读入
//            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
//            data = bufferedReader.readLine();

            data = "{\"UavNum\":\"999999999\",\"State\":\"Takingoff\",\"Lat\":23.9066462,\"Lng\":113.4100651,\"Elevation\":22.66,\"RelativeAlt\":5,\"Yaw\":120.5651,\"Speed\":1.11,\"Time\":\"2022-03-09 17:35:31:310\"}";
            datas = data.getBytes(StandardCharsets.UTF_8);
            datagramPacket = new DatagramPacket(datas, 0, datas.length,new InetSocketAddress("localhost", 19988));
            datagramSocket.send(datagramPacket);
            if(data.trim().equals("bye")){
                datagramSocket.close();
            }
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }
}
